// promise 的链式调用

function interview(round){
    return new Promise((resolve,reject)=>{
        setTimeout(()=>{
            if (Math.random()<0.2){
                const error = new Error('failed');
                error.round = round;
                reject(error);
            }
            else{
                resolve('success')
            }
        },500)
    })
}


interview(1)
    .then(
        ()=>{
            return interview(2)
        }
    )
    .then(
        ()=>{
            return interview(3)
        }
    )
    .then(
        ()=>{
            if(Math.random()>0.8){
                const error = new Error('keyboard')
                error.round = 'keyboard'
                throw error
            }else{
                console.log('all pass,smile now')
            }
    })
    .catch((err)=>{
        console.log('cry at ' + err.round)
    })





